$(function() {
    var transferRecord_datagrid =  $("#transferRecord_datagrid");
    var transferRecord_dialog =  $("#transferRecord_dialog");
    var transferRecord_form =  $("#transferRecord_form");
    //begin列表信息
    transferRecord_datagrid.datagrid({
        url: "/transferRecord/list",
        columns: [[
            {field: "xxx", checkbox: 'true'},
            {field: "id", title: "编号", width: 100,hidden:true},
            {field: "professionalStudent1", title: "用户名", width: 100 ,formatter:function (value,row,index) {
                        if(row.professionalStudent){

                             return row.professionalStudent.name;
                        }
            }},
            {field: "tuition1", title: "总学费", width: 100 ,formatter:function (value,row,index) {
                if(row.tuition){
                     return row.tuition.originaltuition;

                }
            }},
            {field: "tuition2", title: "已交学费", width: 100 ,formatter:function (value,row,index) {
                if(row.tuition){
                    return row.tuition.originaltuition;

                }
             }},
             {field: "tuition3", title: "未交款", width: 100 ,formatter:function (value,row,index) {
                 if(row.tuition){
                     return row.tuition.unpaidaltuition;

                 }
             }},
             {field: "transferrecordDate", title: "转班时间", width: 100 },
             {field: "professionalStudent", title: "联系电话", width: 100 ,formatter:function (value,row,index) {
                 if(value){

                 }
                    return value?value.tell :''

             }},
            {field: "oldgrade", title: "以前班级", width: 100  ,formatter:function (value,row,index) {
                if(value){

                    return value?value.name :''
                }
            }},
            {field: "newgrade", title: "现在班级", width: 100  ,formatter:function (value,row,index) {
                if(value){

                    return value?value.name :''
                }
            }},
            {field: "marketer", title: "营销人员", width: 100  ,formatter:function (value,row,index) {
                if(value){

                return value?value.username :''
                }
            }},
            {field: "satate", title: "状态", width: 100 ,formatter:function (value,row,index) {
                if(value == 0){
                    return '<font color="red">审核中</font>';
                }else if(value == 1){
                    return '<font color="green">审核通过</font>';
                }
            }}
        ]],
        fit: true,
        fitColumns: true,
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        striped: true,
        pageNumber:1,
        pageSize:10,
        pageList:[3,5,10,20],
        toolbar: "#transferRecord_tb"
    });
    //end列表信息

    //begin查看对话框
    transferRecord_dialog.dialog({
        width: 400,
        height: 400,
        buttons: "#transferRecord_bb",
        closed: true
    });
    //end添查看对话框

    //begin处理功能方法的对象
    var obj = {



        //begin查看按钮
        check: function () {
            transferRecord_form.form("clear");
            transferRecord_dialog.dialog("setTitle", "转班学员");
            var row = transferRecord_datagrid.datagrid("getSelected");
            if (!row) {
                $.messager.alert('温馨提示', '请选择要操作的行!');
                return;
            }
            $("#transferRecord_form :input").prop("readonly" ,true);
            if(row){
                row["professionalStudent.name"] = row.professionalStudent.name;
                row["tuition.originaltuition"] = row.tuition.originaltuition;
                row["tuition.paidupcapital"] = row.tuition.paidupcapital;
                row["tuition.unpaidaltuition"] = row.tuition.unpaidaltuition;
                row["professionalStudent.tell"] = row.professionalStudent.tell;
                row["oldgrade.name"] = row.oldgrade.name;
                row["newgrade.name"] = row.newgrade.name;
                row["marketer.username"] = row.marketer.username;

            }
            transferRecord_form.form("load", row);
            transferRecord_dialog.dialog("open");
            transferRecord_form.find("input").attr("readonly",true);
        },
        //end查看按钮


        //begin 审核按钮
        changeState: function (){
            var row = transferRecord_datagrid.datagrid("getSelected");
            if (!row) {
                $.messager.alert('温馨提示', '请选择要操作的行!');
                return;
            }
            $.messager.confirm('审核确认','想好后请点击确认？',function(r){
                if (r){
                    var url = "/transferRecord/changeState?id="+row.id;
                    $.get(url, function(data){

                        if (!data.success) {
                            $.messager.alert('温馨提示', data.msg);
                        } else {
                            $.messager.alert('温馨提示', "操作成功!");

                            transferRecord_datagrid.datagrid("reload");
                        }
                    });
                }
            });

        },
        //end 审核按钮

        // begin转班学员高级查询操作
        query: function() {
            var keywords= $("#keywords").textbox("getValue");
            var beginDate= $("#beginDate").textbox("getValue");
            var endDate= $("#endDate").textbox("getValue");
            transferRecord_datagrid.datagrid("load",{
                keywords:keywords,
                beginDate:beginDate,
                endDate:endDate
            });
        },
        // 转班学员高级查询操作 end


        //begin刷新按钮
        reload:function (){
            transferRecord_datagrid.datagrid("reload")
        }
        //end刷新按钮
    };
    //end处理功能方法的对象

    //begin处理功能方法对象,实际调用方法
    $("a[data-cmd]").click(function(){
        var cmd = $(this).data("cmd");
        obj[cmd]();
    });
    //end处理功能方法对象,实际调用方法

});